<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/commons/taglibs.jsp" %>
<!DOCTYPE html>
<html>
<%@ include file="/commons/head.jsp" %>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <%@ include file="/commons/left.jsp" %>
    <div class="content-wrapper">
        <section class="content-header">
            <h1>
                管理员信息
            </h1>
        </section>
        <div class="content">
            <div class="row">
                <div class="col-md-9">
                    <div class="box box-primary" style="overflow:hidden">
                        <form id="postForm" class="form-horizontal" enctype="multipart/form-data" autocomplete="off">
                            <input type="hidden" name="Id" value="${entity.id}">
                            <div class="box-body" style="padding-top:30px">
                                <div class="form-group">
                                    <label for="inputUserName" class="col-sm-2 control-label">用户名</label>
                                    <div class="col-sm-5">
                                        <input type="text" class="form-control" autocomplete="off" id="inputUserName"
                                               name="userName" value="${entity.userName}" placeholder="请输入用户名">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputPassword" class="col-sm-2 control-label">密码</label>
                                    <div class="col-sm-5">
                                        <input type="password" class="form-control" autocomplete="off"
                                               id="inputPassword" name="password"  value="${entity.password}" placeholder="请输入密码">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="inputMobile" class="col-sm-2 control-label">手机号</label>
                                    <div class="col-sm-3">
                                        <input type="tel" class="form-control" id="inputMobile" name="mobile" value="${entity.mobile}" placeholder="请输入手机号">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="multipartFile" class="col-sm-2 control-label">头像</label>
                                    <div class="col-sm-5">
                                        <input id="multipartFile"  name="multipartFile" type="file"  accept="image/*"
                                               style="margin-top: 5px;">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="realName" class="col-sm-2 control-label">真实姓名</label>
                                    <div class="col-sm-5">
                                        <input type="text" class="form-control" autocomplete="off" id="realName"
                                               name="realName" value="${entity.realName}" placeholder="真实姓名">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="address" class="col-sm-2 control-label">地址</label>
                                    <div class="col-sm-5">
                                        <input type="text" class="form-control" autocomplete="off" id="address"
                                               name="address" value="${entity.address}" placeholder="请输入地址">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="qq" class="col-sm-2 control-label">QQ</label>
                                    <div class="col-sm-5">
                                        <input type="text" class="form-control" autocomplete="off" id="qq"
                                               name="qq" value="${entity.qq}" placeholder="请输入QQ号">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="weChat" class="col-sm-2 control-label">微信</label>
                                    <div class="col-sm-5">
                                        <input type="text" class="form-control" autocomplete="off" id="weChat"
                                               name="weChat" value="${entity.weChat}" placeholder="请输入微信号">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="email" class="col-sm-2 control-label">邮箱</label>
                                    <div class="col-sm-5">
                                        <input type="text" class="form-control" autocomplete="off" id="email"
                                               name="email" value="${entity.email}" placeholder="请输入邮箱">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="selectRole" class="col-sm-2 control-label">角色</label>
                                    <div class="col-sm-3">
                                        <select class="form-control select2 select2-hidden-accessible" id="selectRole"
                                                style="width: 100%;" tabindex="-1" aria-hidden="true" name="roleId">
                                            <option value="0">请选择</option>
                                            <c:forEach var="role" items="${roles}" varStatus="vs">
                                                <option value="${role.id}" <c:if test="${role.id == entity.roleId}">selected="selected"</c:if>>${role.roleName}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="checkbox" class="col-sm-2 control-label">选项</label>
                                    <div class="col-sm-10">
                                        <div class="checkbox col-sm-1">
                                            <label>
                                                <input type="checkbox" id="checkbox" name="disable" <c:if test="${entity.disable==0}">checked="checked"</c:if>>启用
                                            </label>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="box-footer">
                                <div class="col-sm-2"></div>
                                <button type="button" class="btn btn-info" onclick="submitForm()">提交</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <%@ include file="/commons/script.jsp" %>
    <script type="text/javascript" src="${ctx}/dist/js/jquery.form.js"></script>
    <script type="text/javascript">
        function submitForm() {
            var id = $('#postForm').find('input[name=Id]').val();
            var url = null;
            if (id == null || id == "") {
                url = "${ctx}/user/saveUser?action=add";
            } else {
                url = "${ctx}/user/saveUser?action=update";
            }
            var check = $("#postForm").find("input[name='disable']").is(':checked');
            if (check) {
                $("#postForm").find("input[name='disable']").val(0);
            } else {
                $("#postForm").find("input[name='disable']").val(1);
            }
            $("#postForm").ajaxSubmit({
                cache: false,
                type: "post",
                url: url,
                error: function () {
                    alert("系统异常");
                },
                success: function (data) {
                    if (data !== null) {
                        if (data == 0) {
                            //修改失败
                            alert('失败');
                        } else {
                            //添加/修改成功
                            alert('成功');
                            window.location.href="${ctx}/user/listUser";
                        }
                    }
                }
            });
        }
    </script>
</body>
</html>
